package com.lmc.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lmc.R;
import com.lmc.entity.HeartRate;
import com.lmc.util.DateFormatUtil;

import java.util.List;

public class DataFragmentResultAdapter extends BaseAdapter {
    Context context;
    List<HeartRate.DataBean.ResultBean> resultBeanLis;

    public DataFragmentResultAdapter(Context context, List<HeartRate.DataBean.ResultBean> resultBeanLis) {
        this.context = context;
        this.resultBeanLis = resultBeanLis;
    }

    @Override
    public int getCount() {
        return resultBeanLis.size();
    }

    @Override
    public HeartRate.DataBean.ResultBean getItem(int position) {
        return resultBeanLis.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView ==null){
            convertView = View.inflate(context, R.layout.data_fragment_result_list_item,null);
            holder = new ViewHolder();
            holder.value = convertView.findViewById(R.id.value);
            holder.time = convertView.findViewById(R.id.time);
            holder.unit = convertView.findViewById(R.id.unit);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        HeartRate.DataBean.ResultBean bean = getItem(position);
        holder.value.setText(bean.getValue());
        holder.time.setText(DateFormatUtil.forString(bean.getDate(),"HH:mm"));
        holder.unit.setText(bean.getUnit());
        return convertView;
    }

    private class ViewHolder{
        TextView value,time,unit;
    }
}
